﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace WindowsGame1
{
    public class Player : Object
    {
        new public Vector2[] textVector =
        {
            new Vector2(50,500),//hp
            new Vector2(50,530),//ammo
            new Vector2(50,560),//armor
            new Vector2(300,500),//weapon
            new Vector2(300,550),//health
            new Vector2(500,0),//score
        };



        public int HP = 100;
        public int Weapon = 0;
        public int Armor = 100;
        public int EXP = 0;
        public int Ammo = 0;
        public int Ampule = 0;


        public Player()
        {

        }
        public Player(int X, int Y)
        {
            this.coord.X = X;
            this.coord.Y = Y;
        }

        ~Player()
        {

        }

        public override void Dispose()
        {

        }

        public override void ShowInfo(GraphicsDevice graphicsDevice, SpriteBatch spriteBatch, SpriteFont font)
        {
            Texture2D pixel = new Texture2D(graphicsDevice, 1, 1);
            Color[] colorData = { Color.White, };
            pixel.SetData<Color>(colorData);
            spriteBatch.Begin();
            if (HP >= 81)
            {
                spriteBatch.Draw(pixel, new Rectangle((int)coord.X - 35, (int)coord.Y - 15, HP, 10), Color.Green);
            }
            else if (HP >= 61 && HP <= 80)
            {
                spriteBatch.Draw(pixel, new Rectangle((int)coord.X - 35, (int)coord.Y - 15, HP, 10), Color.Yellow);
            }
            else if (HP >= 41 && HP <= 60)
            {
                spriteBatch.Draw(pixel, new Rectangle((int)coord.X - 35, (int)coord.Y - 15, HP, 10), Color.Orange);
            }
            else if (HP >= 21 && HP <= 40)
            {
                spriteBatch.Draw(pixel, new Rectangle((int)coord.X - 35, (int)coord.Y - 15, HP, 10), Color.Red);
            }
            else
            {
                spriteBatch.Draw(pixel, new Rectangle((int)coord.X - 35, (int)coord.Y - 15, HP, 10), Color.DarkRed);
            }

            spriteBatch.Draw(pixel, new Rectangle((int)coord.X - 35, (int)coord.Y - 30, Armor, 10), Color.Gray);
           
            spriteBatch.DrawString(font, "HP     " + this.HP.ToString(), this.textVector[0], Color.White);
            spriteBatch.DrawString(font, "Ammo  " + this.Ammo.ToString(), this.textVector[1], Color.White);
            spriteBatch.DrawString(font, "Armor  " + this.Armor.ToString(), this.textVector[2], Color.White);
            spriteBatch.DrawString(font, "Weapon "+ this.Weapon.ToString() , this.textVector[3], Color.White);
            spriteBatch.DrawString(font, "Healing Ampules "+ this.Ampule.ToString(), this.textVector[4], Color.White);
            spriteBatch.DrawString(font, "SCORE: " + this.EXP.ToString(), this.textVector[5], Color.White);
            spriteBatch.End();
        }

        public void Go(SpriteBatch spriteBatch,KeyboardState CurrentKeyboardState, Texture2D sprite,int frameSize, int frames, Player gracz, ref int playerAnimState)
        {
            // potrzebny sprite w postaci tablicy klatek animacji
            Rectangle source = new Rectangle(frameSize * frames, 0, frameSize, frameSize);
            Rectangle destination = new Rectangle((int)gracz.coord.X, (int)gracz.coord.Y, frameSize, frameSize);
            spriteBatch.Begin();
            if (CurrentKeyboardState.IsKeyDown(Keys.Up))
            {
                source.Y = frameSize * 3;
                playerAnimState = 3;
                spriteBatch.Draw(sprite, destination, source, Color.White);
            }
            if (CurrentKeyboardState.IsKeyDown(Keys.Down))
            {
                source.Y = frameSize * 0;
                playerAnimState = 0;
                spriteBatch.Draw(sprite, destination, source, Color.White);
            }
            if (CurrentKeyboardState.IsKeyDown(Keys.Left))
            {
                source.Y = frameSize * 1;
                playerAnimState = 1;
                spriteBatch.Draw(sprite, destination, source, Color.White);
            }
            if (CurrentKeyboardState.IsKeyDown(Keys.Right))
            {
                source.Y = frameSize * 2;
                playerAnimState = 2;
                spriteBatch.Draw(sprite, destination, source, Color.White);
            }

            source.Y = frameSize*playerAnimState;
            spriteBatch.Draw(sprite, destination, source, Color.White);
            spriteBatch.End();

        }

        public void Shoot()
        {
           
        }

        public void Upgrade()
        {

        }

        public void Die()
        {

        }

        public void ChooseItem()
        {

        }

        public void ShowMenu()
        {

        }

    }
}
